<div class="form">

    <?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'cat-form',
    'enableAjaxValidation' => false,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <?php echo $form->labelEx($model, 'name'); ?>
        <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'name'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'color'); ?>
        <?php echo $form->textField($model, 'color', array('size' => 60, 'maxlength' => 255)); ?>
        <?php echo $form->error($model, 'color'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'birthday'); ?>
        <?php //echo $form->textField($model, 'birthday'); ?>
        <?php  $this->widget('zii.widgets.jui.CJuiDatePicker', array(
        'model'=>$model,
        'attribute'=>'birthday',
        'value'=>$model->birthday,
        'options'=>array(
            'showAnim'=>'fold',
            'showButtonPanel'=>true,
            'autoSize'=>true,
            'dateFormat'=>'yy-mm-dd',
            'showOn' => 'focus',
            'showOtherMonths' => true,
            'selectOtherMonths' => true,
            'changeMonth' => true,
            'changeYear' => true,
        ),
        ));?>
        <?php echo $form->error($model, 'birthday'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'description'); ?>
        <?php echo $form->textArea($model, 'description', array('rows' => 6, 'cols' => 50)); ?>
        <?php echo $form->error($model, 'description'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'sex'); ?>
        <?php echo $form->radioButtonList($model, 'sex', $model->getSexes(), array('size' => 6, 'maxlength' => 6)); ?>
        <?php echo $form->error($model, 'sex'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'type'); ?>
        <?php echo $form->radioButtonList($model, 'type', $model->getTypes(), array('size' => 6, 'maxlength' => 6)); ?>
        <?php echo $form->error($model, 'type'); ?>
    </div>

    <div class="row kitten-parent" style="display: <?php echo ($model->type=='kitten') ? 'block' : 'none' ?> ">
        <?php echo $form->labelEx($model, 'father_id'); ?>
        <?php echo $form->dropDownList($model, 'father_id', $model->getFathers(), array()); ?>
        <?php echo $form->error($model, 'father_id'); ?>
    </div>

    <div class="row kitten-parent" style="display: <?php echo ($model->type=='kitten') ? 'block' : 'none' ?> ">
        <?php echo $form->labelEx($model, 'mother_id'); ?>
        <?php echo $form->dropDownList($model, 'mother_id', $model->getMothers(), array()); ?>
        <?php echo $form->error($model, 'mother_id'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'avatar'); ?>
        <?php echo $form->fileField($model, 'avatar'); ?>
        <?php echo $form->error($model, 'avatar'); ?>
        <?php
        if(!$model->isNewRecord) {
            echo CHtml::image(Yii::app()->baseUrl.'/images/avatars/' .$model->cat_id, $model->name, array('height'=>100));
        }
        ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'del_avatar'); ?>
        <?php echo $form->checkBox($model, 'del_avatar'); ?>
        <?php echo $form->error($model, 'del_avatar'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php if (!$model->isNewRecord && $model->gal_id): ?>
        <div class="row">
            <?php echo CHtml::link(Yii::t('cat', 'Manage photo gallery'),
                array('/imgManager/pl/index', 'galid'=>$model->gal_id))
            ?>
        </div>
    <?php endif?>



    <?php $this->endWidget(); ?>

</div><!-- form -->

<script type="text/javascript">
    $(document).ready(function(){
        $("input:radio[name='Cat[type]']").bind('change',function(){
            if ($("input:radio[name='Cat[type]']:checked").val()=='kitten') {
                $('div.kitten-parent').show();
            } else {
                $('div.kitten-parent').hide();
            }
        });

    });
</script>